import { takeEvery, put } from 'redux-saga/effects'
import { loadProducts, savaProducts } from '../actions/product.actions'
import axios from 'axios'

function* handleLoadProducts ()  {
  const { data } = yield axios.get('http://localhost:3005/goods')
  // 把服务端返回的数据存储到本地store中
  yield put(savaProducts(data))
}

export default function* productSaga() {
  yield takeEvery(loadProducts, handleLoadProducts)
}